//#include //#include #include //////// SERVO AND LED GLOBAL VARIABLES ///////// Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position static int switchPin = PC2; //static int led_pin1 = 10; static int led_pin2 = PD6; static int servo_pin = PD5; int minutes = 60000; // = 1 minuit in milliseconds int track_time(); // time tracking variable using the for_loop void setup() { // set the switch as an input: pinMode(switchPin, INPUT); // set all the other pins you're using as outputs: pinMode(led_pin2, OUTPUT); myservo.attach(servo_pin); // attaches the servo on pin 9 to the servo object } void loop() { delay(2000); if (digitalRead(switchPin) == HIGH) // check if the pushbutton is pressed. If it is, the buttonState is HIGH: { /// Start Servo Control Program /// for (pos = 0; pos <= 178; pos += 1) { // goes from 0 degrees to 178 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(3000); for (pos = 178; pos >= 0; pos -= 1) { // goes from 178 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(6000); /// End of Servo Control Program /// //// DAY 1 /// /// evening light on /// digitalWrite(led_pin2, HIGH); // turn the LED on for (int track_time = 0; track_time <= 180; track_time++) /// Wait for a specified time /// { delay(minutes); } /// morning light off /// digitalWrite(led_pin2, LOW); // turn the LED off for (int track_time = 1; track_time <= 1260; track_time++) { delay(minutes); } //// DAY 1 /// /// evening light on /// digitalWrite(led_pin2, HIGH); // turn the LED on for (int track_time = 0; track_time <= 180; track_time++) /// Wait for a specified time /// { delay(minutes); } /// morning light off /// digitalWrite(led_pin2, LOW); // turn the LED off for (int track_time = 1; track_time <= 1260; track_time++) { delay(minutes); } delay(2000); /// Start Servo Control Program /// for (pos = 0; pos <= 178; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(3000); for (pos = 178; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(3000); for (pos = 0; pos <= 80; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(5); // waits 15ms for the servo to reach the position } /// End of Servo Control Program /// } else { //// DAY 1 /// /// evening light on /// digitalWrite(led_pin2, HIGH); // turn the LED on for (int track_time = 0; track_time <= 180; track_time++) /// Wait for a specified time /// { delay(minutes); } /// morning light off /// digitalWrite(led_pin2, LOW); // turn the LED off for (int track_time = 1; track_time <= 1260; track_time++) { delay(minutes); } //// DAY 1 /// /// evening light on /// digitalWrite(led_pin2, HIGH); // turn the LED on for (int track_time = 0; track_time <= 180; track_time++) /// Wait for a specified time /// { delay(minutes); } /// morning light off /// digitalWrite(led_pin2, LOW); // turn the LED off for (int track_time = 1; track_time <= 1260; track_time++) { delay(minutes); } /// Start Servo Control Program /// for (pos = 0; pos <= 178; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(3000); for (pos = 178; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } delay(3000); /// End of Servo Control Program /// } }